<?php
class retrieve_forum_admin extends retrieve_base{

	private $module_display_options 	= array(
		array("FORUM_DISPLAY","DISPLAY_FORUM_CHANNEL")
	);

	function getDigitalDesktop($p){
		$sql = "
		SELECT forum_identifier, forum_label, count(forum_thread_forum) as total
			FROM forum
				inner join forum_thread on forum_thread_forum = forum_identifier and forum_client = forum_thread_client 
		where forum_thread_status = 0 and forum_client = $this->client_identifier
			group by forum_identifier
		";
		$sql = "SELECT md_title AS forum_label, forum_identifier, count( forum_thread.forum_thread_identifier ) AS unapproved_threads
		FROM forum
		INNER JOIN metadata_details ON md_link_id = forum_identifier
		AND md_client =". $this->client_identifier ."
		AND md_module = 'FORUM_'
		LEFT OUTER JOIN forum_thread ON forum_identifier = forum_thread_forum
		AND forum_thread_status =0
		AND forum_thread_client = forum_client
		WHERE forum_client =" .$this->client_identifier ."
		AND forum_status =1
		GROUP BY forum_identifier
		ORDER BY forum_label";
		
		$result  = $this->db->query($sql);
		$out = "<module name='forum' label='Forum Manager' display='my_workspace'><label>Forums with entries requiring approval</label>";
		$c=0;
        while($r = $this->db->fetch_array($result)){
        	if ($r["unapproved_threads"] > 0){
	  			$out .= "	<text><![CDATA[ <a href='admin/index.php?command=FORUMADMIN_MANAGE_THREADS&amp;identifier=".$r["forum_identifier"]."'>".$r["forum_label"]." (".$r["unapproved_threads"].")</a>]]></text>";
        	}
        	else {
	  			$out .= "	<text><![CDATA[ ".$r["forum_label"]." (".$r["unapproved_threads"].")]]></text>";        		
        	}	
        	$c++;
        }
		if ($c==0){
	  		$out .= "	<text><![CDATA[ There are no Forum Entries to Approve]]></text>";
		}
        $this->db->free_result($result);
  		$out .= "</module>";
		return $out;
	}
	
		/**
	* function produces abstract structure of modules db structure
	*
    * used to generate the table structure required abstract function that passes an abstract
	* representation of the desired table structure to the proper database module which will
	* interpet the abstract and convert it into a valid SQL Create table structure.
	*
	* @return Array list of abstract table definitions for this module
	*/
	function create_table(){
		$tables = array();
		/**
		* Table structure for table 'group_data'
		*/
		$fields = array(
			array("forum_identifier"		,"unsigned integer"			,"NOT NULL"	,"auto_increment"),
			array("forum_client"			,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("forum_date_created"		,"datetime"					,"" 		,"default NULL"),
			array("forum_created_by"		,"unsigned integer"			,"NOT NULL"	,"default ''"),
			array("forum_status"			,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("forum_workflow"			,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("forum_location"			,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("forum_category"			,"integer"					,"NOT NULL"	,"default '-1'")
		);
		$primary ="forum_identifier";
		$tables[count($tables)] = array("forum", $fields, $primary);
		/**
		* Table structure for table 'group_access'
		*/
		$fields = array(
			array("forum_thread_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment"),
			array("forum_thread_forum"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("forum_thread_parent"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("forum_thread_starter"	,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("forum_thread_author"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("forum_thread_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("forum_thread_status"		,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("forum_thread_date"		,"datetime"					,"NOT NULL"	,"default ''"),
			array("forum_thread_blocked"	,"unsigned small integer"	,"NOT NULL"	,"default '0'")
		);
		$primary ="forum_thread_identifier";
		$tables[count($tables)] = array("forum_thread", $fields, $primary);
		/**
		* Table structure for table 'pages'
		*/
		$fields = array(
			array("search_keyword"				,"varchar(50)"		,"NOT NULL"	,"default ''"),
			array("search_counter"				,"unsigned integer"	,"NOT NULL"	,"default '0'"),
			array("search_client"				,"unsigned integer"	,"NOT NULL"	,"default ''")
		);
		$primary ="";
		$tables[count($tables)] = array("forum_search_keys", $fields, $primary);
		/**
		* Table structure for table 'forum_category'
		*/
		$fields = array(
			array("fc_identifier"			,"unsigned integer"	,"NOT NULL"	,"auto_increment"),
			array("fc_client"				,"unsigned integer"	,"NOT NULL"	,"default '0'"),
			array("fc_label"				,"varchar(255)"		,"NOT NULL"	,"default '0'")
		);
		$primary ="fc_identifier";
		$tables[count($tables)] = array("forum_category", $fields, $primary);
		/**
		* Table structure for table 'forum_thread_counter'
		*/
		$fields = array(
			array("ftc_identifier"			,"unsigned integer"	,"NOT NULL"	,"default ''"), // thread owner (starter) allows date and author of first post to be retrieved
			array("ftc_client"				,"unsigned integer"	,"NOT NULL"	,"default '0'"), // client id
			array("ftc_views"				,"unsigned integer"	,"NOT NULL"	,"default '0'"), // times viewed
			array("ftc_posts"				,"unsigned integer"	,"NOT NULL"	,"default '0'"), // total posts to this thread
			array("ftc_lastthread"			,"unsigned integer"	,"NOT NULL"	,"default '0'"), // last thread in list allows date and author of last post to be retrieved
			array("ftc_forum"				,"unsigned integer"	,"NOT NULL"	,"default '0'"), // forum belongs to 
			array("ftc_sticky"				,"unsigned integer"	,"NOT NULL"	,"default '0'") // Sticky thread 
		);
		
		$primary ="";
		$tables[count($tables)] = array("forum_thread_counter", $fields, $primary);
		/**
		* Table structure for table 'forum_thread_counter'
		*/
		$fields = array(
			array("fgr_group"			,"integer"	,"NOT NULL"	,"default ''"), // group to define settings for
			array("fgr_client"			,"unsigned integer"	,"NOT NULL"	,"default '0'"), // client id
			array("fgr_can_view"		,"unsigned integer"	,"NOT NULL"	,"default '0'"), // times viewed
			array("fgr_can_post"		,"unsigned integer"	,"NOT NULL"	,"default '0'"), // total posts to this thread
			array("fgr_auto_publish"	,"unsigned integer"	,"NOT NULL"	,"default '0'"), // last thread in list allows date and author of last post to be retrieved
			array("fgr_forum"			,"unsigned integer"	,"NOT NULL"	,"default '0'") // forum belongs to 
		);
		
		$primary ="";
		$tables[count($tables)] = array("forum_group_restrictions", $fields, $primary);
		return $tables;
	}
}
?>